package com.twu.biblioteca;

import java.util.regex.Pattern;

/**
 * Created by olga on 7/06/14.
 */
public class Movie extends LibraryItem
{
    private String rate;
    private static final String DEFAULT_RATE_VALUE = "unrated";

    public Movie( String title, String director, String year, String rate )
    {
        super(title, director, year);
        itemType = "movie";
        setRate(rate);
    }

    public String getRate() {
        return rate;
    }

    public void setRate(String rate)
    {
        if( rate == null )
            this.rate = DEFAULT_RATE_VALUE;
        else {
            String regex = "^([1-9]\\d*|0)(\\.\\d)?$";
            this.rate = (rate.matches(regex.toString())) ? rate : DEFAULT_RATE_VALUE;
        }
    }
}
